package com.tungse.study.io.three;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class MsgReadThread extends Thread {
    final Socket socket;
    public MsgReadThread(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        //3 从socket中获取输入流，读取客户端发送的数据
        InputStream is = null;
        try {
            is = socket.getInputStream();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is));
            String msg = null;
            while ((msg = bufferedReader.readLine()) != null) {
                System.out.println("服务端接收到客户端发送的消息：" + msg);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

    }
}
